package com.axonactive.yolo.service.internal;

import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.axonactive.yolo.dto.JsonData;

@Service
public class JsonDataService {

	@Autowired
	private DataSource dataSource;
	private String numAdults="1";
	private String numChildren="0";
	private String rangeValue="0";
	

	public JsonData getData(String departureAirportCode, String arrivalAirportCode,
			String tripType, String cabinClass, String inboundDate,
			String outboundDate, String numAdults, String numChildren, String numInfants, String rangeValue) {
		List<JsonData> jsonData = new ArrayList<JsonData>();
		String sql = "select * from tbl_mockdb where departureAirportCode ='"
				+ departureAirportCode + "' and arrivalAirportCode='" + arrivalAirportCode
				+ "' and tripType='" + tripType + "' and cabinClass='"
				+ cabinClass + "' and inboundDate='" + inboundDate
				+ "' and outboundDate='" + outboundDate + "' and numAdults ='"
				+ numAdults + "' and numChildren='" + numChildren+"' and numInfants ='"+numInfants+"' and rangeValue ='"+rangeValue+"'";

		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		jsonData = jdbcTemplate.query(sql, new JsonDataRowMapper());

		return jsonData.get(0);

	}

	public JsonData getData(String departureAirportCode, String arrivalAirportCode,
			String tripType, String cabinClass, String outboundDate,
			String numAdults, String numChildren, String numInfants, String rangeValue) {
		List<JsonData> jsonData = new ArrayList<JsonData>();
		String sql = "select * from tbl_mockdb where departureAirportCode ='"
				+ departureAirportCode + "' and arrivalAirportCode='" + arrivalAirportCode
				+ "' and tripType='" + tripType + "' and cabinClass='"
				+ cabinClass + "' and outboundDate='" + outboundDate
				+ "' and numAdults ='" + numAdults + "' and numChildren='"
				+ numChildren+"' and numInfants ='"+numInfants+"' and rangeValue ='"+rangeValue+"'";

		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		jsonData = jdbcTemplate.query(sql, new JsonDataRowMapper());

		return jsonData.get(0);

	}

	public List<JsonData> getAllJson() {
		List<JsonData> jsonData = new ArrayList<JsonData>();
		String sql = "select * from tbl_mockdb";
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		jsonData = jdbcTemplate.query(sql, new JsonDataRowMapper());
		return jsonData;

	}

}
